package com.cndw.kungfu.domain;

import java.util.Map;

import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.vo.CollectVO;
import com.cndw.kungfu.vo.goodsvo.GoodsVO;

public class Collect {

	private int id;
	private int type; // 1道具类，2装备类，3秘籍类，4徒弟类
	private String name;
	private int goodsId1;
	private int counts1;
	private int goodsId2;
	private int counts2;
	private int goodsId3;
	private int counts3;
	private int goodsId4;
	private int counts4;
	private int goodsId5;
	private int counts5;
	private int goodsId; // 兑换获得物品
	private int counts; // 兑换获得的物品数量
	private int points; // 成就点
	private boolean reiteration; // 是否重复兑换

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getGoodsId1() {
		return goodsId1;
	}

	public void setGoodsId1(int goodsId1) {
		this.goodsId1 = goodsId1;
	}

	public int getCounts1() {
		return counts1;
	}

	public void setCounts1(int counts1) {
		this.counts1 = counts1;
	}

	public int getGoodsId2() {
		return goodsId2;
	}

	public void setGoodsId2(int goodsId2) {
		this.goodsId2 = goodsId2;
	}

	public int getCounts2() {
		return counts2;
	}

	public void setCounts2(int counts2) {
		this.counts2 = counts2;
	}

	public int getGoodsId3() {
		return goodsId3;
	}

	public void setGoodsId3(int goodsId3) {
		this.goodsId3 = goodsId3;
	}

	public int getCounts3() {
		return counts3;
	}

	public void setCounts3(int counts3) {
		this.counts3 = counts3;
	}

	public int getGoodsId4() {
		return goodsId4;
	}

	public void setGoodsId4(int goodsId4) {
		this.goodsId4 = goodsId4;
	}

	public int getCounts4() {
		return counts4;
	}

	public void setCounts4(int counts4) {
		this.counts4 = counts4;
	}

	public int getGoodsId5() {
		return goodsId5;
	}

	public void setGoodsId5(int goodsId5) {
		this.goodsId5 = goodsId5;
	}

	public int getCounts5() {
		return counts5;
	}

	public void setCounts5(int counts5) {
		this.counts5 = counts5;
	}

	public int getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}

	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}

	public int getPoints() {
		return points;
	}

	public void setPoints(int points) {
		this.points = points;
	}

	public boolean isReiteration() {
		return reiteration;
	}

	public void setReiteration(boolean reiteration) {
		this.reiteration = reiteration;
	}
	
	private int getCount(Map<Integer, Integer> goodsCounts,int key){
		if (goodsCounts.containsKey(key)) {
			return goodsCounts.get(key);
		}
		return 0;
	}

	public CollectVO toCollectVO(long playerId, Map<Integer, Integer> goodsCounts) {
		CollectVO collectVO = new CollectVO();
		collectVO.setId(getId());
		collectVO.setType(getType());
		collectVO.setName(getName());

		collectVO.setHasCounts1(getCount(goodsCounts, getGoodsId1()));
		collectVO.setGoodsName1(Context.getGoodsServer().getModeById(getGoodsId1()).getName());
		collectVO.setGoodsId1(getGoodsId1());
		collectVO.setCounts1(getCounts1());

		// goods 2
		if (getGoodsId2() > 0) {
			collectVO.setHasCounts2(getCount(goodsCounts, getGoodsId2()));
			collectVO.setGoodsName2(Context.getGoodsServer().getModeById(getGoodsId2()).getName());
			collectVO.setGoodsId2(getGoodsId2());
			collectVO.setCounts2(getCounts2());
		}

		// goods 3
		if (getGoodsId3() > 0) {
			collectVO.setHasCounts3(getCount(goodsCounts, getGoodsId3()));
			collectVO.setGoodsName3(Context.getGoodsServer().getModeById(getGoodsId3()).getName());
			collectVO.setGoodsId3(getGoodsId3());
			collectVO.setCounts3(getCounts3());
		}

		// goods 4
		if (getGoodsId4() > 0) {
			collectVO.setHasCounts4(getCount(goodsCounts, getGoodsId4()));
			collectVO.setGoodsName4(Context.getGoodsServer().getModeById(getGoodsId4()).getName());
			collectVO.setGoodsId4(getGoodsId4());
			collectVO.setCounts4(getCounts4());
		}

		// goods 5
		if (getGoodsId5() > 0) {
			collectVO.setHasCounts5(getCount(goodsCounts, getGoodsId5()));
			collectVO.setGoodsName5(Context.getGoodsServer().getModeById(getGoodsId5()).getName());
			collectVO.setGoodsId5(getGoodsId5());
			collectVO.setCounts5(getCounts5());
		}

		GoodsVO goods = Context.getGoodsServer().getModeById(getGoodsId()).toGoodsVO();
		goods.setStackNum(getCounts());
		collectVO.setGoodsVO(goods);
		collectVO.setPoints(getPoints());
		collectVO.setReiteration(isReiteration());

		// 兑换状态 1已收集，2收集中，3未收集，4已兑换且不可重复兑换
		if (!isReiteration() && Context.getGeneralServer().checkCollectFinish(playerId, getId())) {
			collectVO.setStatus(4);
		} else {
			int progress = Context.getGeneralServer().checkProgress(goodsCounts, this);
			collectVO.setProgress(progress);
			if (progress == 100) {
				collectVO.setStatus(1);
			} else if (progress > 0) {
				collectVO.setStatus(2);
			} else {
				collectVO.setStatus(3);
			}
		}
		return collectVO;
	}
}
